
package com.joysuch.wwyt.edu.enums;

public enum CertificateTypes {

    LONG_TERM((byte) 1, "长期有效"), LIMITED_MONTHS((byte) 0, "定期有效");

    private byte code;
    private String name;

    private CertificateTypes(byte code, String name) {
        this.code = code;
        this.name = name;
    }

    public byte getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public boolean is(Byte code) {
        return code != null && code.intValue() == this.code;
    }

    public static CertificateTypes findByName(String name) {
        CertificateTypes[] values = CertificateTypes.values();
        for (CertificateTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static CertificateTypes findByCode(Byte code) {
        if (code == null) {
            return null;
        }
        CertificateTypes[] values = CertificateTypes.values();
        for (CertificateTypes v : values) {
            if (v.getCode() == code.intValue()) {
                return v;
            }
        }
        return null;
    }

    public static String findNameByCode(Byte code) {
        CertificateTypes types = findByCode(code);
        return types == null ? null : types.name;
    }
}
